package com.example.controller;

import com.example.common.Result;
import com.example.entity.ZyzStudent;
import com.example.service.ZyzStudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 志愿者学生控制器
 */
@RestController
@RequestMapping("/api/zyzStudent")
public class ZyzStudentController {
    @Autowired
    private ZyzStudentService zyzStudentService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody ZyzStudent zyzStudent) {
        zyzStudentService.add(zyzStudent);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete/batch")
    public Result deleteBatch(String ids) {
        int i = zyzStudentService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result update(@RequestBody ZyzStudent zyzStudent) {
        zyzStudentService.updateById(zyzStudent);
        return Result.success();
    }

    /**
     * 根据id查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ZyzStudent zyzStudent = zyzStudentService.selectById(id);
        return Result.success(zyzStudent);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(ZyzStudent zyzStudent) {
        List<ZyzStudent> list = zyzStudentService.selectAll(zyzStudent);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(ZyzStudent zyzStudent,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ZyzStudent> page = zyzStudentService.selectPage(zyzStudent, pageNum, pageSize);
        return Result.success(page);
    }


}
